/**
 * 
 */
package com.aft.terra.modules.game.controller;

import java.util.Date;

import com.aft.terra.app.Constants;
import com.aft.terra.common.utils.DateUtil;
import com.aft.terra.modules.game.model.GameDetails;
import com.aft.terra.modules.game.model.User;
import com.jfinal.core.Controller;
import com.jfinal.kit.StrKit;
import com.jfinal.validate.Validator;

/**
 * @author Administrator
 *
 */
public class UserValidator extends Validator {

	@Override
	protected void validate(Controller c) {
		String userId = controller.getCookie(Constants.SESSION_NAME);
		User user = User.dao.findById(userId);
		controller.setAttr("notUser", controller.getAttr("notUser"));
		if (StrKit.notBlank(controller.getPara("captcha"))) {
			validateCaptcha("captcha", "message", "验证码不正确");
			validateRequired("phone", "message", "手机号码不能为空");
			controller.setAttr("state", controller.getPara("state"));
			controller.setAttr("notUser", true);
		}
		controller.setAttr("user", user);
	}

	@Override
	protected void handleError(Controller c) {
		controller.keepPara("phone");
		controller.render("/member/addPhone.html");
	}

}
